package com.example.studentinfo.api.controller;

import com.example.studentinfo.api.entity.Student;
import com.example.studentinfo.api.service.StudentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 学生表 前端控制器
 * </p>
 *
 * @author yhan219
 * @since 2022-09-24
 */
@RestController
@RequestMapping("/api/student")
@RequiredArgsConstructor
public class StudentController {

    private final StudentService studentService;


    /**
     * 添加学生
     *
     * @param student
     * @return
     */
    @PostMapping("/add")
    public boolean add(Student student) {
        return student.insert();
    }


    /**
     * 所有学生数据
     *
     * @return
     */
    @GetMapping("/list")
    public List<Student> list() {
        return studentService.list();
    }


    /**
     * 删除学生
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public boolean delete(long id) {
        return studentService.removeById(id);
    }

}